﻿using System;
using System.Data;
using System.Collections.Generic;

using DAL.User;
using Model.User;

namespace BLL.User
{
    public class TravelUserBLL
    {
        private readonly TravelUserDAL dal = new TravelUserDAL();
        public TravelUserBLL()
        { }
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string UserName)
        {
            return dal.Exists(UserName);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(TravelUser model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(TravelUser model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int UserId)
        {

            return dal.Delete(UserId);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string UserIdlist)
        {
            return dal.DeleteList(UserIdlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public TravelUser GetModel(int UserId)
        {

            return dal.GetModel(UserId);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<TravelUser> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<TravelUser> DataTableToList(DataTable dt)
        {
            List<TravelUser> modelList = new List<TravelUser>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                TravelUser model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new TravelUser();
                    if (dt.Rows[n]["USERID"] != null && dt.Rows[n]["USERID"].ToString() != "")
                    {
                        model.Userid = int.Parse(dt.Rows[n]["USERID"].ToString());
                    }
                    if (dt.Rows[n]["SUPPLIERNO"] != null && dt.Rows[n]["SUPPLIERNO"].ToString() != "")
                    {
                        model.Supplierno = int.Parse(dt.Rows[n]["SUPPLIERNO"].ToString());
                    }
                    if (dt.Rows[n]["USERNAME"] != null && dt.Rows[n]["USERNAME"].ToString() != "")
                    {
                        model.Username = dt.Rows[n]["USERNAME"].ToString();
                    }
                    if (dt.Rows[n]["FULLNAME"] != null && dt.Rows[n]["FULLNAME"].ToString() != "")
                    {
                        model.Fullname = dt.Rows[n]["FULLNAME"].ToString();
                    }
                    if (dt.Rows[n]["USERPWD"] != null && dt.Rows[n]["USERPWD"].ToString() != "")
                    {
                        model.Userpwd = dt.Rows[n]["USERPWD"].ToString();
                    }
                    if (dt.Rows[n]["STATUS"] != null && dt.Rows[n]["STATUS"].ToString() != "")
                    {
                        model.Status = dt.Rows[n]["STATUS"].ToString();
                    }
                    if (dt.Rows[n]["REGISTRATIONTIME"] != null && dt.Rows[n]["REGISTRATIONTIME"].ToString() != "")
                    {
                        model.Registrationtime = dt.Rows[n]["REGISTRATIONTIME"].ToString();
                    }
                    if (dt.Rows[n]["LOGINTIME"] != null && dt.Rows[n]["LOGINTIME"].ToString() != "")
                    {
                        model.Logintime = dt.Rows[n]["LOGINTIME"].ToString();
                    }
                    if (dt.Rows[n]["LOGINIP"] != null && dt.Rows[n]["LOGINIP"].ToString() != "")
                    {
                        model.Loginip = dt.Rows[n]["LOGINIP"].ToString();
                    }
                    if (dt.Rows[n]["USERGROUPID"] != null && dt.Rows[n]["USERGROUPID"].ToString() != "")
                    {
                        model.Usergroupid = dt.Rows[n]["USERGROUPID"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }

        #endregion  Method
    }
}
